package dados;

import negocio.TecidoBean;

import org.hibernate.Session;
import java.util.List;

public class CadastrarTecido {

	public void armazenarTecido(String codigo,String descricao) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		TecidoBean t= new TecidoBean();
		t.setCodigo(codigo);
		t.setDescricao(descricao);
		session.save(t);
		session.getTransaction().commit();
		}
	
	public void editarTecido(TecidoBean t,String codigo,String descricao){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		t.setCodigo(codigo);
		t.setDescricao(descricao);
		session.update(t);
		session.getTransaction().commit();	
	}
	public List listar(){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List result = session.createQuery("from TecidoBean").list();
		session.getTransaction().commit();
		return  result;
	}
	
}
